﻿Public Class B1FormListServer
    Private _FormListSetting As B1FormList.B1FormListSetting
    Private WithEvents _B1Form As B1Form
    Private _ListButUID As String
    Private _InputUID As String
    Private _InputCol As String
    Private B1FormList As B1FormList.B1FormList
    Private _ShowMode_ADD As Boolean = True
    Private _ShowMode_OK As Boolean = True
    Private _ShowMode_FIND As Boolean = True
    Private _ShowMode_UPDATE As Boolean = True
    Private TabChar As String = "9"

    Sub New(ByVal B1Form As B1Form)
        B1FormList = B1Addon.B1Addon.B1FormList
        _B1Form = B1Form
    End Sub

    Sub New(ByVal B1Form As B1Form, ByVal InputItemUID As String, ByVal InputItemCol As String, ByVal ButtonList As String)
        B1FormList = B1Addon.B1Addon.B1FormList
        _B1Form = B1Form
        _ListButUID = ButtonList
        _InputCol = InputItemCol
        _InputUID = InputItemUID
    End Sub

    Public Property ShowMode_ADD As Boolean
        Get
            Return _ShowMode_ADD
        End Get
        Set(ByVal value As Boolean)
            _ShowMode_ADD = value
        End Set
    End Property

    Public Property ShowMode_OK As Boolean
        Get
            Return _ShowMode_OK
        End Get
        Set(ByVal value As Boolean)
            _ShowMode_OK = value
        End Set
    End Property

    Public Property ShowMode_FIND As Boolean
        Get
            Return _ShowMode_FIND
        End Get
        Set(ByVal value As Boolean)
            _ShowMode_FIND = value
        End Set
    End Property

    Public Property ShowMode_UPDATE As Boolean
        Get
            Return _ShowMode_UPDATE
        End Get
        Set(ByVal value As Boolean)
            _ShowMode_UPDATE = value
        End Set
    End Property

    Public Property ListButtonUID As String
        Set(ByVal value As String)
            _ListButUID = value
        End Set
        Get
            Return _ListButUID
        End Get
    End Property

    Public Property InputItemUID As String
        Set(ByVal value As String)
            _InputUID = value
        End Set
        Get
            Return _InputUID
        End Get
    End Property

    Public Property InputItemCol As String
        Set(ByVal value As String)
            _InputCol = value
        End Set
        Get
            Return _InputCol
        End Get
    End Property

    Public ReadOnly Property FormListSetting As B1FormList.B1FormListSetting
        Get
            Return GetFormListSetting.Invoke()
        End Get
        'Set(ByVal value As B1FormList.B1FormListSetting)
        '    _FormListSetting = value
        'End Set
    End Property

    Private Sub _B1Form_frm_ItemEvent(ByVal pVal As B1AddonBase.B1ItemEvent, ByRef BubbleEvent As Boolean) Handles _B1Form.frm_ItemEvent
        If pVal.BeforeAction Then
            If (pVal.ItemUID = ListButtonUID And pVal.EventType = SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED) Or _
                (pVal.ItemUID = InputItemUID And pVal.EventType = SAPbouiCOM.BoEventTypes.et_KEY_DOWN And pVal.CharPressed = TabChar And pVal.ColUID = InputItemCol) Then
                CallFormList(pVal, BubbleEvent)
            End If
        Else

        End If
    End Sub

    Private Sub CallFormList(ByVal pVal As B1AddonBase.B1ItemEvent, ByRef BubbleEvent As Boolean)
        Dim oform As SAPBoAddon.B1Objects.Form
        Dim ItemValue As String
        Dim ItemEx As SAPBoAddon.B1Objects.IItem
        Try
            oform = Me._B1Form.CurrentFormEx
            If oform.Mode = SAPbouiCOM.BoFormMode.fm_ADD_MODE And Me.ShowMode_ADD = False Then Exit Sub
            If oform.Mode = SAPbouiCOM.BoFormMode.fm_OK_MODE And Me.ShowMode_OK = False Then Exit Sub
            If oform.Mode = SAPbouiCOM.BoFormMode.fm_UPDATE_MODE And Me.ShowMode_UPDATE = False Then Exit Sub
            If oform.Mode = SAPbouiCOM.BoFormMode.fm_FIND_MODE And Me.ShowMode_FIND = False Then Exit Sub
            ItemEx = oform.ItemsEx.ItemEx(Me.InputItemUID)
            If ItemEx.Type = SAPbouiCOM.BoFormItemTypes.it_MATRIX Then
                ItemValue = ItemEx.GetValue()
            Else
                ItemValue = ItemEx.GetValue()
            End If
            'If String.IsNullOrEmpty(ItemValue) = False And pVal.CharPressed = TabChar Then Exit Sub
            If Me.B1FormList.Form_CreateListForm(Me.FormListSetting) Is Nothing Then
            Else
                BubbleEvent = False
            End If
        Catch ex As Exception
            Throw New Exception(ex.Message & "by avaformlist.")
        End Try
    End Sub

    Public GetFormListSetting As GetB1FormListSetting

End Class


Public Delegate Function GetB1FormListSetting()
